package view
{
	import com.common.Color;
	import com.common.TempData;
	import com.loader.XMLLoader;
	import com.util.MakeChildrenUtil;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	import view.renderer.Renderer14;
	
	import xm.components.button.SWCButton;
	import xm.util.XmlParsingUtil;
	import xm.view.ViewList;
	
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 강석민
	 */	
	public class View14_XmlParsing extends ViewList
	{
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function View14_XmlParsing()
		{
			super();
		}
		
		/**
		 * commitProperties
		 */		
		override public function commitProperties():void
		{
			super.commitProperties();
		}
		
		/**
		 * updateDisplayList
		 */		
		override public function updateDisplayList( enforce : Boolean = false ):void
		{
			super.updateDisplayList(enforce);
		}
		
		//-----------------------------------------------------------------------------------
		// life cycle functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * createChildren
		 */		
		override public function createChildren():void
		{
			super.createChildren();
			
			//============================================================
			//						액션바
			//============================================================
			//네비게이션컨텐츠
			var navigationBtn : SWCButton = MakeChildrenUtil.makeSwcBtn( new BTN_PREV );
			this.navigationContent = MakeChildrenUtil.makeNavigationContent( navigationBtn );
			//타이틀 컨텐츠
			var titleTextField : TextField = MakeChildrenUtil.makeTextField( "View14_XmlParsing", Color.WHITE, 20 );
			this.titleContent  = MakeChildrenUtil.makeTitleContent( titleTextField );
			//액션컨텐츠
			var actionBtn : SWCButton = MakeChildrenUtil.makeSwcBtn( new BTN_NEXT ); 
			this.actionContent = MakeChildrenUtil.makeActionContent( actionBtn );
			actionBtn.addEventListener(MouseEvent.CLICK , onActionBtnClick );
			//============================================================
			//						화면구성
			//============================================================
			
			//List Setting
			this.itemRenderer				= Renderer14;
			this.gapBetweenItem 			= 0;
			this.itemHeight 				= 50;
			this.padding 					= [0,0,0,0];
			this.scrollColor 				= 0xff0000;
		}
		
		
		/**
		 * createComplete
		 */		
		override public function creationComplete():void
		{
			super.creationComplete();
		}
		
		/**
		 * add
		 */		
		override public function add():void
		{
			super.add();
		}
		
		/**
		 * startAddTransition : add 완료 후 transition 이 있으면 화면전환효과를 실행한다.
		 */		
		override public function startAddTransition():void
		{
			super.startAddTransition();
		}
		
		/**
		 * startAddTransition 완료.
		 */		
		override public function endAddTransition():void
		{
			super.endAddTransition();
			
			loadData();
		}
		
		/**
		 * startRemoveTransition : remove 하기 전 transition 이 있으면 화면전환효과를 실행한다.
		 */		
		override public function startRemoveTransition():void
		{
			super.startRemoveTransition();
		}
		
		/**
		 * startRemoveTransition 완료.
		 */		
		override public function endRemoveTransition():void
		{
			super.endRemoveTransition();
		}
		
		/**
		 * remove
		 */		
		override public function remove():void
		{
			super.remove();
		}
		
		/**
		 * destroy
		 */		
		override public function destroy():void
		{
			super.destroy();
		}
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		/**
		 * Data Load
		 */
		private function loadData():void
		{
			XMLLoader.instance.load( new URLRequest( "./assets/getMenuList.xml" ) );
			XMLLoader.instance.addEventListener( Event.COMPLETE , onXmlLoadComplete );
		}
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		/**
		 *
		 */
		private function onActionBtnClick(e:MouseEvent):void
		{
			this.navigator.add( View15_StageWebView );
		}
		/**
		 *
		 */
		private function onXmlLoadComplete(e:Event):void
		{
			var pmis : XML = new XML( XMLLoader.instance.data );
			/*
			<pmis>
				<menu>
					<menuId>A0001</menuId>
					<menuNm>공지사항</menuNm>
					<dep>1</dep>
					<url/>
					<param/>
					<uppMenuId/>
					<app/>
					<cnt>0</cnt>
				</menu>
				<menu>
					<menuId>A0010</menuId>
					<menuNm>일반공지사항</menuNm>
					<dep>2</dep>
					<url/>
					<param>001010</param>
					<uppMenuId>A0001</uppMenuId>
					<app>Y</app>
					<cnt>0</cnt>
				</menu>
				<menu>
					<menuId>A0010</menuId>
					<menuNm>일반공지사항</menuNm>
					<dep>2</dep>
					<url/>
					<param>001010</param>
					<uppMenuId>A0001</uppMenuId>
					<app>Y</app>
					<cnt>0</cnt>
				</menu>
			</pmis>
			*/
			//	menu		XML 리스트를 만듬
			var resultList : Array = XmlParsingUtil.getListFromResultData( pmis, "menu" );
			
			// menu였다면 이걸 써도 된다.
			var resultObject : Object = XmlParsingUtil.getObjFromResultData( pmis, "menu" );
			
			// dep 가 1인 menu 리스트의 menuNm
			var dep1ListOfResultList : Array = XmlParsingUtil.findItemAndGetList( pmis.menu, "dep", "1", "menuNm" );
			
			// menuId 가 A0010 인 menu
			var menuIdResultObj : Object = XmlParsingUtil.findItemAndGetObj( pmis.menu, "menuId", "A0010", "menuNm" );
			
			this.dataProvider = resultList;
			this.invalidateDisplayList();
		}
		
		
	}
}